<?php
	require_once('config.php');
	if(!DEBUG)
		header('Content-type: text/vnd.wap.wml');
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card title="Kien's wap">
	<p>	
<?php
define("MAX_LINK",7);
define('doc_root','../');
$path = $_REQUEST['path'];
$name = $_REQUEST['name'];
$start   = $_REQUEST['start'] ? $_REQUEST['start'] : '0';
//$ext  = $_REQUEST['ext'];
$no = 0;
$ls = glob( doc_root."/$path/$name" );
if(!$start) $start = 0;
echo "Duyet thu muc <b>$path:</b><br />Trang ". (int)($start/MAX_LINK+1)."<br />\n";
//foreach (glob("/$path/$name.$ext") as $filename) {
foreach ( $ls as $no=>$filename ) {
	if($no >= $start){
		if($no >= ($start + MAX_LINK)) break;
			if(!is_dir($filename)) 
				$href = doc_root."/$path/".basename($filename);
			else
				$href = "dir.php?path=$path/".basename($filename)."&name=$name";
			echo "$no. <a href=\"$href\">" . basename($filename) .  "</a> &nbsp; size " . filesize($filename) . "<br />\n";
	}
}
echo "<a href=\"dir.php?path=$path&name=$name&start=". ($start - MAX_LINK) ."\">prev</a>&nbsp;";
echo "<a href=\"dir.php?path=$path&name=$name&start=$no\">next</a><br />";

echo <<<KIEN
\n<input format="*N" name="no" size="3" value="$no"/>
<anchor>
	<go href="dir.php" method="get">
		<postfield name="path" value="$path"/>
		<postfield name="name" value="$name"/>
		<postfield name="start" value="\$(no)"/>
	</go>
	Go to page
</anchor><br />\n
KIEN;
echo "<a href=\"./\">back</a>\n";
?>
	</p>
<do type="options" label="Tải lại">
	<refresh />
</do>
</card>
</wml>
